package com.sfac.springboot.springboot.modules.common.service.impl;

import com.sfac.springboot.springboot.modules.common.dao.ExceptionLogDao;
import com.sfac.springboot.springboot.modules.common.entity.ExceptionLog;
import com.sfac.springboot.springboot.modules.common.service.ExceptionLogService;
import com.sfac.springboot.springboot.modules.common.vo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.time.LocalDateTime;

@Service
public class ExceptionLogServiceImpl implements ExceptionLogService {

    @Autowired
    private ExceptionLogDao exceptionLogDao;
    @Override
    @Transactional
    public Result<ExceptionLog> insertExceptionLog(ExceptionLog exceptionLog) {
            ExceptionLog temp = exceptionLogDao.getELByPathAnName(
                    exceptionLog.getPath(),exceptionLog.getExceptionType());
            if (temp != null){
                return new Result<ExceptionLog>(
                        Result.ResultStatus.SUCCESS.code,"异常信息已经存在.");
            }

        exceptionLog.setCreateDate(LocalDateTime.now());
        exceptionLog.setUpdateDate(LocalDateTime.now());

        exceptionLogDao.insertExceptionLog(exceptionLog);

        return new Result<ExceptionLog>(
                Result.ResultStatus.SUCCESS.code,"插入成功",exceptionLog);
    }
}
